<style>
.product-color,.product-size {margin: 0 !important}
.p-color-holder input:checked ~ .product-color,.p-size-holder input:checked ~ .product-size
 {border: 1px solid orange;}
</style>
<div class="row">
	<div class="box col-md-12">
		<div class="box-inner">
			<div class="box-header well">
				<h2><i class="glyphicon glyphicon-user"></i> Danh sách sản phẩm</h2>
				<div class="box-icon">
					<a href="#" class="btn btn-minimize btn-round btn-default"><i class="glyphicon glyphicon-chevron-up"></i></a>
					<a href="#" class="btn btn-close btn-round btn-default"><i class="glyphicon glyphicon-remove"></i></a>
				</div>
			</div>
			<div class="box-content"><?php
			echo form_open(null,array(
				'class'=>'form-horizontal','role'=>'form'
			));
				?><div class="form-group">
					<label class="col-sm-3 col-md-3 col-lg-2 control-label">Tên sản phẩm:</label>
					<div class="col-sm-3 col-md-3"><?php
						echo form_input(array(
							'name'=>'ten','value'=>set_value('ten', $product->getName()),
							'class'=>'form-control','required'=>'required',
							'placeholder'=>'Tiêu đề sản phẩm'
						));
						echo form_error('ten');
					?></div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 col-md-3 col-lg-2 control-label">Chủng loại:</label>
					<div class="col-sm-3 col-md-3"><?php
						$val = array();
						foreach($cat as $v)
							$val[$v->getId()] = $v->getName();
						echo form_dropdown('chung-loai', $val, set_value('ten',$product->getCategory()->getId()), 'class="form-control"');
						echo form_error('chung-loai');
					?></div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 col-md-3 col-lg-2 control-label">Hình đại diện:</label>
					<div class="col-sm-3 col-md-3">
						<span class="thumbnail" id="image_trigger" data-toggle="modal" data-target="#gallery_selector" data-url="<?php echo site_url(); ?>"><?php
							$img = $product->getImage();
							if(empty($img)):
								$img = '';
								$val = null;
							else:
								$val = $img->getId();
								$img = site_url().'/assets/upload/'.$img->getName();
							endif;
							?><img src="<?php echo $img; ?>" />
						</span>
						<input type="hidden" id="avatar_image" name="thumb" value="<?php echo set_value('ten', $val); ?>" /><?php
						echo form_error('thumb');
					?>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 col-md-3 col-lg-2 control-label">Màu sắc:</label>
					<div class="col-sm-4 col-md-4 p-color-holder"><?php
						foreach($list_color as $v):
							echo '<label class="form-label" data-toggle="tooltip" data-placement="top" title="Màu '.html_escape($v->getName()).'" style="margin-right:5px">';
							if(in_array($v->getId(), $color))
								$check = 'checked="checked"';
							else
								$check = null;
							echo '<input type="checkbox" name="color[]" value="'.$v->getId().'" '.$check.' class="hidden">
								<span class="thumbnail product-color"><span style="background: #'
								.html_escape($v->getVal()).'; padding: 5px 20px"></span></span>';
							echo '</label>';
						endforeach;
					?></div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 col-md-3 col-lg-2 control-label">Kích thước:</label>
					<div class="col-sm-3 col-md-3 p-size-holder"><?php
						foreach($list_size as $v):
							echo '<label class="form-label" style="margin-right:5px">';
							if(in_array($v->getId(), $size))
								$check = 'checked="checked"';
							else
								$check = null;
							echo '<input type="checkbox" name="size[]" value="'.$v->getId().'" '.$check.' class="hidden">
								<span class="product-size thumbnail">'.
								$v->getVal().'</span>';
							echo '</label>';
						endforeach;
					?></div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 col-md-3 col-lg-2 control-label">Đơn giá:</label>
					<div class="col-sm-3 col-md-3"><?php
						echo form_input(array(
							'name'=>'gia','value'=>set_value('gia', $product->getPrice()),
							'class'=>'form-control','required'=>'required',
							'placeholder'=>'Tiêu đề sản phẩm'
						));
						echo form_error('gia');
					?></div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 col-md-3 col-lg-2 control-label">Số lượng:</label>
					<div class="col-sm-3 col-md-3"><?php
						echo form_input(array(
							'name'=>'so-luong','value'=>set_value('so-luong', $product->getQuantity()),
							'class'=>'form-control','required'=>'required',
							'placeholder'=>'Tiêu đề sản phẩm'
						));
						echo form_error('ten');
					?></div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 col-md-3 col-lg-2 control-label">Chi tiết:</label>
					<div class="col-sm-9"><?php
						echo form_textarea(array(
							'name'=>'chi-tiet','value'=>set_value('ten', $product->getContent()),
							'class'=>'form-control bbcode','required'=>'required',
							'placeholder'=>'Thông tin chi tiết'
						));
						echo form_error('chi-tiet');
					?></div>	
				</div>
				<div class="form-group">
					<div class="col-sm-3 col-md-3 col-sm-push-2"><?php
						echo form_submit(array(
							'name'=>'submit','value'=>'Sửa bài viết',
							'class'=>'btn btn-success'
						)).' '.form_reset(array(
							'name'=>'reset','value'=>'Nhập lại',
							'class'=>'btn btn-warning'
						));
					?></div>
				</div>
				<?php
			echo form_close();
			?></div>
		</div>
	</div>
</div>
<div class="modal fade" id="gallery_selector" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title" id="myModalLabel">Hình ảnh</h4>
      </div>
      <div class="modal-body">
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Đóng</button>
        <button type="button" class="btn btn-primary" id="gallery_submit">Chọn hình</button>
      </div>
    </div>
  </div>
</div>
<script>
$('.product-color').click(function(){
	console.log('asd');
});
$('#gallery_selector').on('show.bs.modal', function (event) {
	$('#gallery_selector .modal-body').load($('#image_trigger').data('url')+"admin/gallery/");
});
$('#gallery_submit').click(function(e){
	var select = $('#gallery_selector .modal-body .ui-selected');
	if(select.length) {
		$('#avatar_image').val(select.data('id'));
		$('#image_trigger').find('img').attr('src', select.data('img')).fadeOut().fadeIn();
		$('#gallery_selector').modal('hide');
	} else
		e.stopImmediatePropagation();
});
$(document).on('click', '#gallery_selector ul.pagination a', function(e){
	e.stopPropagation();
	var href = $(this).attr('href');
	$('#gallery_selector .modal-body').html('<p class="text-center">Đang tải, xin chờ</p>').load(href);
	return false;
});
</script>